/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package edu.upn.sigemfi.vfi.bc;

import edu.upn.sigemfi.ope.be.Ventanilla;
import edu.upn.sigemfi.ope.bc.VentanillaFacadeLocal;
import java.util.List;
import java.util.logging.Level;
import java.util.logging.Logger;
import javax.naming.Context;
import javax.naming.InitialContext;
import javax.naming.NamingException;

/**
 *
 * @author Alex
 */
public class VentanillaDelegate {
    private VentanillaFacadeLocal local;

    public VentanillaDelegate() {
        local = lookupVentanillaFacade();
    }

      public Ventanilla buscar(Long codigo) throws Exception {
        try {
            return local.find(codigo);
        } catch (Exception e) {
            local = lookupVentanillaFacade();
            throw new Exception("Buscar Ventanilla. " + e.getMessage(), e);
        }
    }
    public List<Ventanilla> listar() throws Exception {
        try {
          
            return local.findAll();
        } catch (Exception e) {
            local = lookupVentanillaFacade();
            throw new Exception("Listar Ventanilla. " + e.getMessage(), e);
        }
    }



    private VentanillaFacadeLocal lookupVentanillaFacade() {
        try {
            Context c = new InitialContext();
            return (VentanillaFacadeLocal) c.lookup("java:comp/env/VentanillaFacade");
        } catch (NamingException ne) {
            Logger.getLogger(getClass().getName()).log(Level.SEVERE, "exception caught", ne);
            throw new RuntimeException(ne);
        }
    }



}
